﻿#include <QFile>
#include "CTaskListWidget.h"
#include "CHeader.h"
#include <QSqlRecord>
#include "CSqlOper.h"
CTaskListWidget::CTaskListWidget(QString sSceneGuid, CRBaseData* pBasicData, QWidget *parent)
	: m_sGuid(sSceneGuid),m_pBasicData(pBasicData),QWidget(parent)
{
	ui.setupUi(this);
	setStyleSheetFile();
	initData();
	initTableView();
	m_pTimer = new QTimer(this);
	m_pTimer->setTimerType(Qt::TimerType::PreciseTimer);
	connect(m_pTimer, &QTimer::timeout, this, &CTaskListWidget::slotDataRefresh);
}

CTaskListWidget::~CTaskListWidget()
{
	m_pTimer->stop();
	if (m_pTimer != nullptr)
	{
		delete m_pTimer;
		m_pTimer = nullptr;
	}

	if (m_pModel != nullptr)
	{
		delete m_pModel;
		m_pModel = nullptr;
	}
}

void CTaskListWidget::loadTaskExec()//加载当天需要执行的任务
{
	m_mapTaskExecRecord.clear();

	//任务数据直接从数据库取任务,然后根据生成列表
	//执行Sql查询语句
	QVector<QSqlRecord> vecRecord;
	QString sErrMsg = "";
	selectAllTaskInfo(m_sGuid, vecRecord, sErrMsg);
	int nCount = vecRecord.size();
	if (0 == nCount)
	{
		return;
	}

	//遍历找到的当天的任务 定时任务和立即执行任务 生成对应所有的子任务
	for (int i = 0; i < nCount; i++)
	{
		//先判断任务类型
		int nTaskType = vecRecord[i].value("TASK_TYPE").toInt();//任务类型
		QString sTaskGuid = vecRecord[i].value("GUID").toString();//任务GUID
		QString sTaskName = vecRecord[i].value("TASK_NAME").toString();//任务名称
		QDateTime dtScheduledTime = vecRecord[i].value("SCHEDULED_TIME").toDateTime();//定时时间(可以使定时时间/立即执行任务时间)
		QString sTemplateFixedId = vecRecord[i].value("TEMPLATE_FIXED_ID").toString();//模板Guid
		switch (nTaskType)
		{
		case enInterTask://定时任务类型
		{
			addTimedTask(m_mapTaskExecRecord, dtScheduledTime, sTaskGuid, sTaskName, sTemplateFixedId);           //添加当天的一个定时任务	
			break;
		}
		case enAtOnceTask://立即执行任务类型
		{
			//先查看执行时间是否是当天的 添加个立即执行任务
			if (judgeIsSameDate(dtScheduledTime))//是当天
			{
				addRunNowTask(m_mapTaskExecRecord, dtScheduledTime, sTaskGuid, sTaskName, sTemplateFixedId);
			}
			break;
		}
		default:
			break;
		}
	}

	/*从任务规则表查询*/
	QVector<QSqlRecord> vecPerTaskRecord;
	selectPerTaskInfo(m_sGuid, vecPerTaskRecord, sErrMsg);
	//遍历找到的当天的任务 定时任务和立即执行任务 生成对应所有的子任务
	for (int i = 0; i < vecPerTaskRecord.size(); i++)
	{
		int nTimeType = vecPerTaskRecord[i].value("TIME_TYPE").toInt();         //时间类型
		QString sTaskGuid = vecPerTaskRecord[i].value("TASK_GUID").toString();     //任务Guid
		QString sSceneGuid = vecPerTaskRecord[i].value("SCENE_GUID").toString();    //场景Guid
		QString sTaskName = vecPerTaskRecord[i].value("TASK_NAME").toString();//任务名称
		QString sTemplateFixedId = vecPerTaskRecord[i].value("TEMPLATE_FIXED_ID").toString();//模板Guid
		addCycleTask(m_mapTaskExecRecord, nTimeType, sTaskGuid, sTaskName, sTemplateFixedId);
	}

	//===========然后加载到表格中=============
	QVector<CTaskExecRecord> vecValidTask = m_mapTaskExecRecord.values().toVector();
	m_pModel->removeRows(0, m_pModel->rowCount());
	m_pModel->setRowCount(vecValidTask.size());
	int n = vecValidTask.size();
	int nRowIndex = 0;//行
	for (CTaskExecRecord uTaskInfo : vecValidTask)
	{
		int nCol = 0;//列
		//序号
		m_pModel->setItem(nRowIndex, nCol, new QStandardItem(QString::number(nRowIndex + 1)));
		m_pModel->item(nRowIndex, nCol)->setTextAlignment(Qt::AlignCenter);
		m_pModel->item(nRowIndex, nCol)->setForeground(QBrush(QColor(255, 255, 255)));

		//任务名称
		m_pModel->setItem(nRowIndex, nCol + 1, new QStandardItem(uTaskInfo.m_sTaskName));
		m_pModel->item(nRowIndex, nCol + 1)->setTextAlignment(Qt::AlignCenter);
		m_pModel->item(nRowIndex, nCol + 1)->setForeground(QBrush(QColor(255, 255, 255)));

		//任务开始时间
		m_pModel->setItem(nRowIndex, nCol + 2, new QStandardItem(uTaskInfo.m_dtTaskStartTime.toString("yyyy/MM/dd hh:mm:ss")));
		m_pModel->item(nRowIndex, nCol + 2)->setTextAlignment(Qt::AlignCenter);
		m_pModel->item(nRowIndex, nCol + 2)->setForeground(QBrush(QColor(255, 255, 255)));

		//任务执行状态
		QString strExecState = "";//任务执行状态
		switch (uTaskInfo.m_nExecState)
		{
		case 0:
			strExecState = A2T("未执行");
			m_pModel->setItem(nRowIndex, nCol + 3, new QStandardItem(strExecState));
			break;
		case 1:
			strExecState = A2T("已执行");
			m_pModel->setItem(nRowIndex, nCol + 3, new QStandardItem(strExecState));
			break;
		case 2:
			strExecState = A2T("执行中");
			m_pModel->setItem(nRowIndex, nCol + 3, new QStandardItem(strExecState));
			break;
		case 3:
			strExecState = A2T("任务中止");
			m_pModel->setItem(nRowIndex, nCol + 3, new QStandardItem(strExecState));
			break;
		case 4:
			strExecState = A2T("已过期");
			m_pModel->setItem(nRowIndex, nCol + 3, new QStandardItem(strExecState));
			break;
		default:
			strExecState = A2T("未知状态");
			m_pModel->setItem(nRowIndex, nCol + 3, new QStandardItem(strExecState));
			break;
		}
		m_pModel->item(nRowIndex, nCol + 3)->setTextAlignment(Qt::AlignCenter);
		m_pModel->item(nRowIndex, nCol + 3)->setForeground(QBrush(QColor(255, 255, 255)));

		QString sEndActTime = "";
		QString sStartPower = "";
		QString sEndPower = "";
		QString sItemNum = "";
		QString sActItemNum = "";
		QString sAlarmItemNum = "";
		//已经执行
		if (0 != uTaskInfo.m_nExecState && 4 != uTaskInfo.m_nExecState)
		{
			sEndActTime = uTaskInfo.m_dtTaskEndTime.toString("yyyy/MM/dd hh:mm:ss");
			sStartPower = QString::number(uTaskInfo.m_dTaskStartPower) + " %";
			sEndPower = QString::number(uTaskInfo.m_dTaskEndPower) + " %";
			sItemNum = QString::number(uTaskInfo.m_nItemNum);
			sActItemNum = QString::number(uTaskInfo.m_nActItemNum);
			sAlarmItemNum = QString::number(uTaskInfo.m_nAlarmItemNum);
		}
		//巡检项总数
		m_pModel->setItem(nRowIndex, nCol + 4, new QStandardItem(sItemNum));
		m_pModel->item(nRowIndex, nCol + 4)->setTextAlignment(Qt::AlignCenter);
		m_pModel->item(nRowIndex, nCol + 4)->setForeground(QBrush(QColor(255, 255, 255)));

		//已执行巡检项数
		m_pModel->setItem(nRowIndex, nCol + 5, new QStandardItem(sActItemNum));
		m_pModel->item(nRowIndex, nCol + 5)->setTextAlignment(Qt::AlignCenter);
		m_pModel->item(nRowIndex, nCol + 5)->setForeground(QBrush(QColor(255, 255, 255)));

		//报警的巡检项数
		m_pModel->setItem(nRowIndex, nCol + 6, new QStandardItem(sAlarmItemNum));
		m_pModel->item(nRowIndex, nCol + 6)->setTextAlignment(Qt::AlignCenter);
		if (sAlarmItemNum.toInt() > 0)
		{
			m_pModel->item(nRowIndex, nCol + 6)->setForeground(QBrush(QColor(255, 0, 0)));
		}
		else
		{
			m_pModel->item(nRowIndex, nCol + 6)->setForeground(QBrush(QColor(255, 255, 255)));
		}
		nRowIndex++;
	}
}

void CTaskListWidget::refreshList()
{
	if (!isVisible())
	{
		return;
	}
	//首先先将列表清空
	m_pModel->removeRows(0, m_pModel->rowCount());
	//刷新CRBasicDataBase中的数据
	if (m_pBasicData->m_pMutex->tryLock(200))
	{
		//首先将数组根据时间倒序排
		int n = 0;
		qSort(m_pBasicData->m_vecTaskExecInfo.begin(), m_pBasicData->m_vecTaskExecInfo.end(), sortExecInfo);
		for (int i = 0; i < m_pBasicData->m_vecTaskExecInfo.size(); i++)
		{
			bool bAlarm = false;
			CTaskExecInfo info = m_pBasicData->m_vecTaskExecInfo[i];
			QList<QStandardItem*> item;
			item.append(new QStandardItem(QString::number(n++)));//序号
			item.append(new QStandardItem(info.m_sTaskName));//任务名称
			item.append(new QStandardItem(info.m_sStartTime));//任务开始时间
			item.append(new QStandardItem(m_mapExecStatus[info.m_nExecState]));//任务执行状态
			item.append(new QStandardItem(QString::number(info.m_nItemCount)));//巡检项数
			item.append(new QStandardItem(QString::number(info.m_nExecItemCount)));//已执行巡检项数
			item.append(new QStandardItem(QString::number(info.m_nAlarmItemCount)));//报警项数
			item.append(new QStandardItem(QString::number(info.m_nCollectAlarmCount)));//持续巡检项报警项数
			if (info.m_nAlarmItemCount > 0 || info.m_nCollectAlarmCount > 0)
			{
				bAlarm = true;
			}
			//设置居中显示
			for (int nRow = 0; nRow < item.count(); nRow++)
			{
				item.at(nRow)->setTextAlignment(Qt::AlignCenter);
				if (bAlarm)//存在报警  则将这一行字体变红
				{
					item.at(nRow)->setForeground(QBrush(QColor(255, 0, 0)));
				}
				else
				{
					item.at(nRow)->setForeground(QBrush(QColor(255, 255, 255)));
				}
			}
			m_pModel->insertRow(m_pModel->rowCount(), item);
		}

		//遍历待执行的任务
		qSort(m_pBasicData->m_vecTaskInfo.begin(), m_pBasicData->m_vecTaskInfo.end(), sortTaskInfo);
		for (int i = 0; i < m_pBasicData->m_vecTaskInfo.size(); i++)
		{
			CTaskInfo info = m_pBasicData->m_vecTaskInfo[i];
			QList<QStandardItem*> item;
			item.append(new QStandardItem(QString::number(n++)));//序号
			item.append(new QStandardItem(info.m_sTaskName));//任务名称
			item.append(new QStandardItem(info.m_sTaskActTime));//任务开始时间
			item.append(new QStandardItem(A2T("待执行")));//任务执行状态
			item.append(new QStandardItem("/"));//巡检项数
			item.append(new QStandardItem("/"));//已执行巡检项数
			item.append(new QStandardItem("/"));//报警项数
			item.append(new QStandardItem("/"));//持续巡检项报警项数
			//设置居中显示
			for (int nRow = 0; nRow < item.count(); nRow++)
			{
				item.at(nRow)->setTextAlignment(Qt::AlignCenter);
				item.at(nRow)->setForeground(QBrush(QColor(255, 255, 255)));
			}
			m_pModel->insertRow(m_pModel->rowCount(), item);
		}
		m_pBasicData->m_pMutex->unlock();
	}
}

void CTaskListWidget::addTimedTask(QMap<QDateTime, CTaskExecRecord> &mapSubTaskInfoSearchRecord, QDateTime dTimingTime, QString sTaskGuid, QString sTaskName, QString sTemplateFixedId)
{
	QString sToday = QDateTime::currentDateTime().toString("yyyy/MM/dd");
	QString sTime = dTimingTime.toString("hh:mm:ss");
	QString sTaskString = sToday + " " + sTime;
	QDateTime qTaskTime = QDateTime::fromString(sTaskString, "yyyy/MM/dd hh:mm:ss");

	/*查询当天的定时任务结果*/
	QVector<CTaskExecInfo> vecTaskExec;
	QString sErrMsg;
	bool bRet = selectTaskExecByDate(sTaskGuid, sToday, vecTaskExec, sErrMsg);
	if (bRet)
	{
		for (int i = 0; i < vecTaskExec.size(); i++)
		{
			CTaskExecInfo uTaskExec = vecTaskExec[i];
			CTaskExecRecord uSubTaskInfo;
			uSubTaskInfo.m_sTaskGuid = sTaskGuid;                 //任务Guid
			uSubTaskInfo.eTaskType = enInterTask;                 //定时任务类型
			uSubTaskInfo.m_sTaskName = sTaskName;                 //任务名称
			uSubTaskInfo.m_sTemplateGuid = sTemplateFixedId;      //模板Guid
			uSubTaskInfo.m_dtTaskStartTime = QDateTime::fromString(uTaskExec.m_sStartTime, "yyyy/MM/dd hh:mm:ss");           //任务开始时间
			uSubTaskInfo.m_nExecState = uTaskExec.m_nExecState;   //0 未执行

			//任务已执行 加入其他数据
			if (0 != uSubTaskInfo.m_nExecState)
			{
				uSubTaskInfo.m_dtTaskEndTime = QDateTime::fromString(uTaskExec.m_sEndTime, "yyyy/MM/dd hh:mm:ss");//任务结束时间
				uSubTaskInfo.m_dTaskStartPower = uTaskExec.m_dStartPower;//任务开始电量
				uSubTaskInfo.m_dTaskEndPower = uTaskExec.m_dEndPower;//任务结束电量
				uSubTaskInfo.m_nItemNum = uTaskExec.m_nItemCount;//巡检项数
				uSubTaskInfo.m_nActItemNum = uTaskExec.m_nExecItemCount;//巡检项数
				uSubTaskInfo.m_nAlarmItemNum = uTaskExec.m_nAlarmItemCount;//巡检项数
			}
			mapSubTaskInfoSearchRecord.insert(uSubTaskInfo.m_dtTaskStartTime, uSubTaskInfo);
		}

		if (vecTaskExec.size() == 0)//说明没有执行记录,要判断是未执行还是过期了
		{
			CTaskExecRecord uSubTaskInfo;
			uSubTaskInfo.m_sTaskGuid = sTaskGuid;                 //任务Guid
			uSubTaskInfo.eTaskType = enInterTask;                 //定时任务类型
			uSubTaskInfo.m_sTaskName = sTaskName;                 //任务名称
			uSubTaskInfo.m_sTemplateGuid = sTemplateFixedId;      //模板Guid
			uSubTaskInfo.m_dtTaskStartTime = qTaskTime;           //任务开始时间
			//判断此时任务时间是否过期
			if (judgeIsOutTime(qTaskTime))
			{
				uSubTaskInfo.m_nExecState = 4;//过期
			}
			else
			{
				uSubTaskInfo.m_nExecState = 0;//未执行
			}
			mapSubTaskInfoSearchRecord.insert(qTaskTime, uSubTaskInfo);
		}
	}
	else
	{
		return;
	}
}

void CTaskListWidget::addCycleTask(QMap<QDateTime, CTaskExecRecord> &mapSubTaskInfoSearchRecord, int nTimeType, QString sTaskGuid, QString sTaskName, QString sTemplateFixedId)
{
	QString sToday = QDateTime::currentDateTime().toString("yyyy/MM/dd");
	QString sTime = m_mapTimeType.value(nTimeType);
	QString sTaskTime = sToday + " " + sTime;
	QDateTime qTaskTime = QDateTime::fromString(sTaskTime, "yyyy/MM/dd hh:mm:ss");

	CTaskExecInfo uTaskExec;
	QString sErrMsg;
	bool bRet = selectTaskExecByDateTime(sTaskGuid, sTaskTime, uTaskExec, sErrMsg);
	if (bRet)
	{
		CTaskExecRecord uSubTaskInfo;
		uSubTaskInfo.m_sTaskGuid = sTaskGuid;                 //任务Guid
		uSubTaskInfo.eTaskType = enPerTask;                   //任务类型
		uSubTaskInfo.m_sTaskName = sTaskName;                 //任务名称
		uSubTaskInfo.m_sTemplateGuid = sTemplateFixedId;      //模板Guid
		uSubTaskInfo.m_nExecState = uTaskExec.m_nExecState;   //任务执行状态

		//任务已执行 加入其他数据
		if (0 != uSubTaskInfo.m_nExecState)
		{
			uSubTaskInfo.m_dtTaskStartTime = QDateTime::fromString(uTaskExec.m_sStartTime, "yyyy/MM/dd hh:mm:ss");           //任务开始时间
			uSubTaskInfo.m_dtTaskEndTime = QDateTime::fromString(uTaskExec.m_sEndTime, "yyyy/MM/dd hh:mm:ss");//任务结束时间
			uSubTaskInfo.m_dTaskStartPower = uTaskExec.m_dStartPower;//任务开始电量
			uSubTaskInfo.m_dTaskEndPower = uTaskExec.m_dEndPower;//任务结束电量
			uSubTaskInfo.m_nItemNum = uTaskExec.m_nItemCount;//巡检项数
			uSubTaskInfo.m_nActItemNum = uTaskExec.m_nExecItemCount;//巡检项数
			uSubTaskInfo.m_nAlarmItemNum = uTaskExec.m_nAlarmItemCount;//巡检项数
		}
		else if (0 == uSubTaskInfo.m_nExecState)//没找到执行记录或者找到了但是未执行
		{
			if (judgeIsOutTime(qTaskTime))
			{
				uSubTaskInfo.m_dtTaskStartTime = qTaskTime;           //任务开始时间
				uSubTaskInfo.m_nExecState = 4;//过期
			}
			else
			{
				uSubTaskInfo.m_dtTaskStartTime = qTaskTime;           //任务开始时间
				uSubTaskInfo.m_nExecState = 0;//未执行

			}
		}
		mapSubTaskInfoSearchRecord.insert(uSubTaskInfo.m_dtTaskStartTime, uSubTaskInfo);
	}
	else
	{
		return;
	}
}

void CTaskListWidget::addRunNowTask(QMap<QDateTime, CTaskExecRecord> &mapSubTaskInfoSearchRecord, QDateTime dExecTime, QString sTaskGuid, QString sTaskName, QString sTemplateFixedId)
{
	QVector<CTaskExecInfo> vecTaskExec;
	QString sErrMsg;
	bool bRet =selectTaskExecByDate(sTaskGuid, dExecTime.date().toString("yyyy/MM/dd"), vecTaskExec, sErrMsg);
	if (bRet)
	{
		for (int i = 0; i < vecTaskExec.size(); i++)
		{
			CTaskExecInfo uTaskExec = vecTaskExec[i];
			CTaskExecRecord uSubTaskInfo;
			uSubTaskInfo.m_sTaskGuid = sTaskGuid;                 //任务Guid
			uSubTaskInfo.eTaskType = enAtOnceTask;                //任务类型
			uSubTaskInfo.m_sTaskName = sTaskName;                 //任务名称
			uSubTaskInfo.m_sTemplateGuid = sTemplateFixedId;      //模板Guid
			uSubTaskInfo.m_nExecState = uTaskExec.m_nExecState;   //0 未执行

			//任务已执行 加入其他数据
			if (0 != uSubTaskInfo.m_nExecState)
			{
				uSubTaskInfo.m_dtTaskStartTime = QDateTime::fromString(uTaskExec.m_sStartTime, "yyyy/MM/dd hh:mm:ss");//任务开始时间
				uSubTaskInfo.m_dtTaskEndTime = QDateTime::fromString(uTaskExec.m_sEndTime, "yyyy/MM/dd hh:mm:ss");//任务结束时间
				uSubTaskInfo.m_dTaskStartPower = uTaskExec.m_dStartPower;//任务开始电量
				uSubTaskInfo.m_dTaskEndPower = uTaskExec.m_dEndPower;//任务结束电量
				uSubTaskInfo.m_nItemNum = uTaskExec.m_nItemCount;//巡检项数
				uSubTaskInfo.m_nActItemNum = uTaskExec.m_nExecItemCount;//巡检项数
				uSubTaskInfo.m_nAlarmItemNum = uTaskExec.m_nAlarmItemCount;//巡检项数
			}
			mapSubTaskInfoSearchRecord.insert(uSubTaskInfo.m_dtTaskStartTime, uSubTaskInfo);
		}
		if (vecTaskExec.size() == 0)
		{
			CTaskExecRecord uSubTaskInfo;
			uSubTaskInfo.m_sTaskGuid = sTaskGuid;                 //任务Guid
			uSubTaskInfo.eTaskType = enAtOnceTask;                 //定时任务类型
			uSubTaskInfo.m_sTaskName = sTaskName;                 //任务名称
			uSubTaskInfo.m_sTemplateGuid = sTemplateFixedId;      //模板Guid
			uSubTaskInfo.m_dtTaskStartTime = dExecTime;           //任务开始时间
			//判断此时任务时间是否过期
			if (judgeIsOutTime(dExecTime))
			{
				uSubTaskInfo.m_nExecState = 4;//过期
			}
			else
			{
				uSubTaskInfo.m_nExecState = 0;//未执行
			}
			mapSubTaskInfoSearchRecord.insert(dExecTime, uSubTaskInfo);
		}
	}
	else
	{
		return;
	}
	return;
}

bool CTaskListWidget::judgeIsSameDate(const QDateTime dDateTime)
{
	// 获取输入时间的日期部分
	QDate dDate = dDateTime.date();

	// 检查日期是否相同
	return dDate == QDateTime::currentDateTime().date();
}

bool CTaskListWidget::judgeIsOutTime(const QDateTime dActTime)
{
	QDateTime currentDateTime = QDateTime::currentDateTime();
	QDateTime oneMinuteBefore = currentDateTime.addSecs(-60); // 当前时间1分钟前
	QDateTime oneMinuteAfter = currentDateTime.addSecs(60);  // 当前时间1分钟后

	if (dActTime >= oneMinuteBefore && dActTime <= oneMinuteAfter)
	{
		// 传入时间在当前时间1分钟前后内，任务待执行
		return false;
	}
	else if (dActTime < currentDateTime.addSecs(-60))
	{
		// 传入时间在当前时间之前且大于1分钟，认为过期
		return true;
	}
	else if (dActTime > currentDateTime.addSecs(60))
	{
		// 传入时间大于当前时间，且超过1分钟，认为未执行
		return false;
	}
	return true;
}

void CTaskListWidget::setStyleSheetFile()
{
	/*QString sQssPath = ":/qss/styleSheet.css";
	QFile qss(sQssPath);
	qss.open(QFile::ReadOnly);
	this->setStyleSheet(qss.readAll());*/
}

void CTaskListWidget::initTableView()
{
	m_pModel = new QStandardItemModel(this);
	//禁止编辑
	ui.tableView->setEditTriggers(QAbstractItemView::NoEditTriggers);
	//单选行
	ui.tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
	//模式为单选
	ui.tableView->setSelectionMode(QAbstractItemView::SingleSelection);
	ui.tableView->setSelectionBehavior(QAbstractItemView::SelectRows);  // 整行选中
	//行末尾自动拉伸填充
	ui.tableView->horizontalHeader()->setStretchLastSection(true);
	//左边序号列隐藏
	ui.tableView->verticalHeader()->setVisible(false);
	QStringList headerListAction;		//水平表头
	headerListAction << A2T("序号") << A2T("任务名称") << A2T("任务开始时间") <<
		A2T("任务执行状态") << A2T("巡检项数") << A2T("已执行巡检项数")<< A2T("报警巡检项数")<<A2T("持续巡检项报警项数");

	QList<quint16> listColumnWidth;		//列宽
	listColumnWidth << 50 << 120 << 150 << 100 << 100 << 150 << 120 <<150;

	//设置列数
	m_pModel->setColumnCount(headerListAction.count());
	//设置表头
	m_pModel->setHorizontalHeaderLabels(headerListAction);
	ui.tableView->setModel(m_pModel);
	//设置列宽
	for (int i = 0; i < listColumnWidth.count(); i++)
	{
		ui.tableView->setColumnWidth(i, listColumnWidth.at(i));
	}
}

void CTaskListWidget::initData()
{
	m_mapExecStatus.clear();
	m_mapExecStatus.insert(0, A2T("未执行"));
	m_mapExecStatus.insert(1, A2T("已执行"));
	m_mapExecStatus.insert(2, A2T("执行中"));
	m_mapExecStatus.insert(3, A2T("任务终止"));
	m_mapExecStatus.insert(4, A2T("过期"));

	m_mapTimeType.insert(0, A2T("00:00:00"));
	m_mapTimeType.insert(1, A2T("00:30:00"));
	m_mapTimeType.insert(2, A2T("01:00:00"));
	m_mapTimeType.insert(3, A2T("01:30:00"));
	m_mapTimeType.insert(4, A2T("02:00:00"));
	m_mapTimeType.insert(5, A2T("02:30:00"));
	m_mapTimeType.insert(6, A2T("03:00:00"));
	m_mapTimeType.insert(7, A2T("03:30:00"));
	m_mapTimeType.insert(8, A2T("04:00:00"));
	m_mapTimeType.insert(9, A2T("04:30:00"));

	m_mapTimeType.insert(10, A2T("05:00:00"));
	m_mapTimeType.insert(11, A2T("05:30:00"));
	m_mapTimeType.insert(12, A2T("06:00:00"));
	m_mapTimeType.insert(13, A2T("06:30:00"));
	m_mapTimeType.insert(14, A2T("07:00:00"));
	m_mapTimeType.insert(15, A2T("07:30:00"));
	m_mapTimeType.insert(16, A2T("08:00:00"));
	m_mapTimeType.insert(17, A2T("08:30:00"));
	m_mapTimeType.insert(18, A2T("09:00:00"));
	m_mapTimeType.insert(19, A2T("09:30:00"));

	m_mapTimeType.insert(20, A2T("10:00:00"));
	m_mapTimeType.insert(21, A2T("10:30:00"));
	m_mapTimeType.insert(22, A2T("11:00:00"));
	m_mapTimeType.insert(23, A2T("11:30:00"));
	m_mapTimeType.insert(24, A2T("12:00:00"));
	m_mapTimeType.insert(25, A2T("12:30:00"));
	m_mapTimeType.insert(26, A2T("13:00:00"));
	m_mapTimeType.insert(27, A2T("13:30:00"));
	m_mapTimeType.insert(28, A2T("14:00:00"));
	m_mapTimeType.insert(29, A2T("14:30:00"));

	m_mapTimeType.insert(30, A2T("15:00:00"));
	m_mapTimeType.insert(31, A2T("15:30:00"));
	m_mapTimeType.insert(32, A2T("16:00:00"));
	m_mapTimeType.insert(33, A2T("16:30:00"));
	m_mapTimeType.insert(34, A2T("17:00:00"));
	m_mapTimeType.insert(35, A2T("17:30:00"));
	m_mapTimeType.insert(36, A2T("18:00:00"));
	m_mapTimeType.insert(37, A2T("18:30:00"));
	m_mapTimeType.insert(38, A2T("19:00:00"));
	m_mapTimeType.insert(39, A2T("19:30:00"));

	m_mapTimeType.insert(40, A2T("20:00:00"));
	m_mapTimeType.insert(41, A2T("20:30:00"));
	m_mapTimeType.insert(42, A2T("21:00:00"));
	m_mapTimeType.insert(43, A2T("21:30:00"));
	m_mapTimeType.insert(44, A2T("22:00:00"));
	m_mapTimeType.insert(45, A2T("22:30:00"));
	m_mapTimeType.insert(46, A2T("23:00:00"));
	m_mapTimeType.insert(47, A2T("23:30:00"));
}

void CTaskListWidget::slotDataRefresh()
{
	refreshList();
}

